package top.mataiji.manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.mataiji.manager.pojo.Collect;
import top.mataiji.manager.pojo.vo.CollectVo;
import top.mataiji.manager.service.CollectServer;
import top.mataiji.manager.util.Result;

import java.sql.Timestamp;
import java.util.List;

/**
 * @Auther: zhaoss
 * @Date: 2021/4/9 - 04 - 09 - 15:52
 * @Description: top.mataiji.manager.controller
 * @version: 1.0
 */
@RestController
@RequestMapping("collect")
public class CollectController {

    @Autowired
    CollectServer collectServer;

    @RequestMapping("addCollect")
    public Result addCollect(Collect collect){
        collect.setDate(new Timestamp(System.currentTimeMillis()));
        Integer integer = collectServer.insertCollect(collect);
        if(integer!=null&&integer!=0){
            return Result.success("添加成功");
        } else {
            return Result.error("添加失败");
        }
    }

    /**
     * 根据userid查询收藏
     * @param userid
     * @return
     */
    @RequestMapping("select")
    public List<CollectVo> selectCollect(Integer userid){
        return collectServer.selectCollect(userid);
    }

    /**
     * 删除收藏
     * @param id
     * @return
     */
    @RequestMapping("delect")
    public Result delectCollect(Integer id){
        Integer integer = collectServer.delectCollectById(id);
        if(integer!=null&&integer!=0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

}
